package com.gaussian.property.app.controller;

import com.gaussian.property.app.service.ProjectReportService;
import com.gaussian.property.app.vo.AppProjectReport;
import com.gaussian.property.module.biz.entity.AppUser;
import com.gaussian.property.module.biz.vo.projectreport.PageQueryProjectReportRequest;
import com.songqi.common.core.domain.R;
import com.songqi.common.core.domain.page.PageDataInfo;
import com.songqi.common.core.validationgroup.AppGroup;
import com.songqi.common.web.request.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.groups.Default;

/**
 * @description:
 * @author: songqi(13776346982)
 * @date: 2024/8/11 22:29
 */
@Api(tags = "项目报告下载")
@Validated
@RestController
@RequestMapping("report/")
public class ProjectReportController extends BaseController {

    @Resource
    private ProjectReportService projectReportService;

    @ApiOperation("分页查询项目报告")
    @PostMapping("pageQueryProjectReport")
    public R<PageDataInfo<AppProjectReport>> pageQueryProjectReport(@RequestBody @Validated({Default.class, AppGroup.class}) PageQueryProjectReportRequest queryRequest) {
        AppUser appUser = (AppUser) getTokenUser();

        PageDataInfo<AppProjectReport> pageData = projectReportService.pageQueryProjectReport(queryRequest, appUser.getAppUserId());
        return success(pageData);
    }


    @ApiOperation("分页查询项目报告下载记录")
    @PostMapping("pageQueryProjectReportDownloadRecord")
    public R<PageDataInfo<AppProjectReport>> pageQueryProjectReportDownloadRecord(@RequestBody @Validated({Default.class, AppGroup.class}) PageQueryProjectReportRequest queryRequest) {
        AppUser appUser = (AppUser) getTokenUser();
        PageDataInfo<AppProjectReport> pageData = projectReportService.pageQueryProjectReportDownloadRecord(queryRequest, appUser.getAppUserId());
        return success(pageData);
    }


    @ApiOperation("标记已下载")
    @PutMapping("markDownload")
    public R<Void> markDownload(String projectReportFileId){
        AppUser appUser = (AppUser) getTokenUser();
        projectReportService.markDownload(projectReportFileId, appUser.getAppUserId());
        return success();
    }


    @ApiOperation("删除下载记录")
    @DeleteMapping("deleteDownloadRecord")
    public R<Void> deleteDownloadRecord(String projectReportFileDownloadRecordId){
        projectReportService.deleteDownloadRecord(projectReportFileDownloadRecordId);
        return success();
    }



}
